<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style>
        html,body{
            height: 100%;
        }
        *{padding: 0;margin: 0;}
        .box{
            width: 400px;
            height: 300px;
            background: pink;
            position: absolute;
            display: none;
        }
        .box span{
            position:absolute;
            top: 0;
            right: 0;
            cursor: pointer;
        }
    </style>
</head>
<body>
<input type="button" value="登录">
<div class="box">
    <span>关闭</span>
</div>
</body>
</html>
<script src="js/jquery-1.10.1.js"></script>
<script>
    $(function(){
        $(window).resize(function(){
            auto();

        });
        function auto(){
            var  bodywidth=$(document.body).outerWidth();
            var  bodyheight=$(document.body).outerHeight();
            var  loginwidth=$(".box").outerWidth();
            var  loginheight=$(".box").outerHeight();
            $(".box").css({
                left:(bodywidth - loginwidth) / 2,
                top:(bodyheight -loginheight) / 2})}
        auto();
        $("input").click(function(){
            $(".box").show("sdf");
            return false
        })
        $("span").click(function(){
            $(".box").hide("dsf");
        })
    })
</script>

